<template>
	<div>

		<el-card>
			<el-button type="primary" @click="open">
				<i class="el-icon-plus"></i>
				添加通知
			</el-button>

			<el-table v-loading="loading" :data="list.data" height="700" border style="width: 100%;margin-top: 20px;">
				<el-table-column prop="time" label="日期">
					<template slot-scope="scop">
						{{$formatDate(scop.row.time)}}
					</template>
				</el-table-column>
				<el-table-column prop="title" label="标题">
				</el-table-column>
				<el-table-column prop="url" label="路径">
				</el-table-column>
				<el-table-column label="上线 " width="100">
					<template slot-scope="scop">
						<el-switch v-model="scop.row.show" :active-value="1" :inactive-value="0"
							@change="changeSwitch(scop.row.show,scop.row.id)"></el-switch>
					</template>
				</el-table-column>
				<el-table-column prop="index" label="排序">
				</el-table-column>
				<el-table-column fixed="right" label="操作" width="150">
					<template slot-scope="scope">
						<el-button @click="edit(scope.row)" size="small" type="primary">
							<i class="el-icon-edit"></i>
						</el-button>
						<el-popconfirm title="确定删除吗？" @confirm="delActivity(scope.row)">
							<el-button slot="reference" size="small" type="danger">
								<i class="el-icon-delete"></i>
							</el-button>
						</el-popconfirm>
					</template>
				</el-table-column>
			</el-table>
			<div style="margin-top: 20px;"></div>
			<Pagination :total="list.total " @SizeChange='SizeChange' @CurrentChange='CurrentChange' />
		</el-card>




	</div>
</template>

<script>
	import add from './components/add.vue';
	import Pagination from '@/components/pagination';
	export default {
		components: {
			add,
			Pagination
		},
		data() {
			return {
				list: [],
				size: 10,
				page: 1,
				loading: true
			};
		},

		created() {
			this.jiazai()
		},
		methods: {
			changeSwitch(e, id) {
				this.axios.post("/admin/user/upNotice", {
					id: id,
					show: e
				}).then(res => {

				}).catch(error => {})
			},
			delActivity(e) {
				this.axios.post("/admin/user/delNotice", {
					id: e.id
				}).then(res => {
					this.$message.success({
						message: "删除成功",
						onClose: (res) => {
							location.reload()
						}
					})
				}).catch(error => {})
			},
			SizeChange(e) {
				this.size = e.size;
				this.page = e.page;
				this.jiazai()
			},
			CurrentChange(e) {
				console.log(e)
				this.size = e.size;
				this.page = e.page;
				this.jiazai()
			},
			open() {
				this.$router.push("/addNotice")
			},
			edit(e) {
				this.$router.push("/addNotice?id="+e.id)
				
			},
			jiazai() {
				this.axios.post("/api/index/findNotice", {
					page: this.page,
					size: this.size,
				
				}).then(res => {
					this.list = res;
					this.loading = false;
				}).catch(error => {

				})
			},

		}
	};
</script>


<style>


</style>
